package com.gdpu.project.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.gdpu.project.service.XsxtService;
import com.opensymphony.xwork2.ActionSupport;

public class TLoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name;
	private String password;
	private HttpServletRequest request;
	private HttpSession session;
	private XsxtService xsxtService;//验证用户存在否

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setService(XsxtService xsxtService) {
		this.xsxtService = xsxtService;
	}

	@Override
	public String execute() throws Exception {
		request = ServletActionContext.getRequest();
		session = request.getSession();
		session.getServletContext();
		Boolean flag=xsxtService.exitUser(getName(),getPassword());//验证登录
		if(flag){
			request.setAttribute("username", getName());
			return "succ";
		}else{
			request.setAttribute("error","登录失败！");
			return "fail";
		}

		
	}

}
